package com.hgxd.controller;

import com.aliyuncs.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.entity.vo.RobotTaskPointHistoryPoVo;
import com.hgxd.result.Result;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;


import com.hgxd.service.IRobotTaskPointHistoryService;
import com.hgxd.entity.RobotTaskPointHistory;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 巡检测点历史记录 前端控制器
 * </p>
 *
 * @author wtf
 * @since 2023-12-01
 */
@Api(tags = "机器人巡检测点历史记录")
@RestController
@RequestMapping("/api/robot-task-point-history")
public class RobotTaskPointHistoryController {
    @Resource(name = "RobotTaskPointHistoryServiceImpl")
    private IRobotTaskPointHistoryService robotTaskPointHistoryService;

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "无需传入id")
    @ApiImplicitParam(name = "robotTaskPointHistory", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人巡检测点历史记录-新增", operType = "新增", operContent = "新增")
    public Result<Boolean> insert(@RequestBody RobotTaskPointHistory robotTaskPointHistory) {
        return Result.ok(robotTaskPointHistoryService.save(robotTaskPointHistory));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "必须传入id")
    @ApiImplicitParam(name = "robotTaskPointHistory", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人巡检测点历史记录-修改", operType = "修改", operContent = "修改")
    public Result<Boolean> update(@RequestBody RobotTaskPointHistory robotTaskPointHistory) {
        return Result.ok(robotTaskPointHistoryService.updateById(robotTaskPointHistory));
    }


    /**
     * 查询全部
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询全部", notes = "无需传参")
    @OperationLogAnnotation(operModule = "机器人巡检测点历史记录-查询全部", operType = "查询", operContent = "查询全部")
    public Result<List<RobotTaskPointHistory>> findAll() {
        return Result.ok(robotTaskPointHistoryService.list());
    }

    /**
     * 根据id查询一个
     */
    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据id查询一个", notes = "传入id")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "机器人巡检测点历史记录-根据id查询一个", operType = "查询", operContent = "根据id查询一个")
    public Result<RobotTaskPointHistory> findOne(@PathVariable Integer id) {
        return Result.ok(robotTaskPointHistoryService.getById(id));
    }

    /**
     * 分页模糊查询
     */
    @PostMapping("/get/page")
    @ApiOperation(value = "分页模糊查询", notes = "传入对应所需参数")
    @OperationLogAnnotation(operModule = "机器人巡检测点历史记录-分页模糊查询", operType = "查询", operContent = "分页模糊查询")
    public Result<Page<RobotTaskPointHistory>> findPage(@RequestBody RobotTaskPointHistoryPoVo robotTaskPointHistoryPoVo) {
        LambdaQueryWrapper<RobotTaskPointHistory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(robotTaskPointHistoryPoVo.getPointName()),RobotTaskPointHistory::getPointName,robotTaskPointHistoryPoVo.getPointName());
        return Result.ok(robotTaskPointHistoryService.page(new Page<>(robotTaskPointHistoryPoVo.getPageNum(), robotTaskPointHistoryPoVo.getPageSize()), lambdaQueryWrapper));
    }
}

